package com.ruoyi.server.enums;


import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.order.enums.OrderStatusEnum;

import java.util.ArrayList;
import java.util.List;

/**
 * 状态：0:草稿；1：发布；2：完成；3：开始
 */
public enum TaskStateEnum {

    DRAFT(0, "草稿"),
    RELEASE(1, "发布"),
    COMPLETE(2, "完成"),
    BEGIN(3, "开始"),
    ;


    private Integer code;
    private String describe;

    private static List<Integer> taskStateEnumList = new ArrayList<>();

    static {
        taskStateEnumList.add(DRAFT.getCode());
        taskStateEnumList.add(RELEASE.getCode());
        taskStateEnumList.add(COMPLETE.getCode());
        taskStateEnumList.add(BEGIN.getCode());
    }

    TaskStateEnum(Integer code, String describe) {
        this.code = code;
        this.describe = describe;
    }

    public static TaskStateEnum getByCode(Integer code) {
        switch (code) {
            case 0:
                return DRAFT;
            case 1:
                return RELEASE;
            case 2:
                return COMPLETE;
            case 3:
                return BEGIN;
            default:
                throw new RuntimeException("状态码错误");
        }
    }

    public static String getByCodeToApp(Integer code) {
        switch (code) {
            case 1:
                return "未开始";
            case 2:
                return "已完成";
            case 3:
                return "进行中";
            default:
                throw new RuntimeException("状态码错误");
        }
    }

    public Integer getCode() {
        return code;
    }

    public String getDescribe() {
        return describe;
    }

    /**
     * 是否存在，是否合法
     *
     * @param code
     * @return
     */
    public static Boolean isExist(Integer code) {
        return taskStateEnumList.contains(code);
    }

}
